package com.tedu._05springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BMIController {
    @GetMapping("/bmi")
    @ResponseBody
    public String calculateBMI(double weight, double height) {
        Double bmi = weight / (height * height);
        System.out.println(bmi);
        if (bmi < 18.5) {
            return "偏瘦";
        } else if ( bmi >= 18.5 && bmi < 24.9) {
            return "正常";
        } else if (bmi >= 24.9 && bmi < 27) {
            return "偏胖";
        } else {
            return "该减肥了";
        }
    }

    @GetMapping("/bmi2/{height}/{weight}")
    @ResponseBody
    public String calculateBMI2(@PathVariable double height,@PathVariable double weight) {
        Double bmi = weight / (height * height);
        System.out.println(bmi);
        if (bmi < 18.5) {
            return "偏瘦";
        } else if ( bmi >= 18.5 && bmi < 24.9) {
            return "正常";
        } else if (bmi >= 24.9 && bmi < 27) {
            return "偏胖";
        } else {
            return "该减肥了";
        }
    }
}
